function bindCaptchaBtnClick() {
    let captcha_btn = $('#captcha');
    captcha_btn.click(function () {
        let email = $('input[name="email"]').val();
        if (!email) {
            alert('请输入邮箱!');
            return;
        }
        $.ajax({
            url: '/user/captcha',
            method: 'POST',
            data: {'email': email},
            success: function (result) {
                if (result.code === 200) {
                    // 关闭点击事件
                    captcha_btn.off('click');
                    // 设置定时器
                    let countDown = 60
                    let timer = setInterval(function () {
                        countDown -= 1;
                        if (countDown > 0) {
                            captcha_btn.text(countDown + '秒后重新发送');
                        } else {
                            captcha_btn.text('获取验证码');
                            // 倒计时结束,重新绑定点击事件,并清空定时器
                            bindCaptchaBtnClick();
                            clearInterval(timer);
                        }

                    }, 1000)
                } else {
                    alert(result.message)
                }
            }
        })
    })
}

$(function () {
    bindCaptchaBtnClick();
})